Imports System.Xml
Imports DotNetNuke.UI.Utilities
Imports System.Web.UI

Partial Class MasterPage
    Inherits System.Web.UI.MasterPage

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        MSAJAX.Register(Me.Page)
        MSAJAX.RegisterClientScript(Me.Page, "MasterPage.master.js")

    End Sub

    'Private m_sHeaderImageUrl As String = "~/images/WebControlsHeader.gif"

    'Public Property HeaderImageUrl() As String
    '    Get
    '        Return m_sHeaderImageUrl
    '    End Get
    '    Set(ByVal Value As String)
    '        m_sHeaderImageUrl = Value
    '    End Set
    'End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SetupMenu()
        If ClientAPI.BrowserSupportsFunctionality(ClientAPI.ClientFunctionality.Motion) Then
            ClientAPI.RegisterClientReference(Me.Page, ClientAPI.ClientNamespaceReferences.dnn_motion)
        End If
        'Me.hdr.Style.Add("background-image", "url(" & ResolveUrl(HeaderImageUrl) & ")")

    End Sub

    Private Sub SetupMenu()

        Me.NavMenu.RenderMode = System.Enum.Parse(GetType(DotNetNuke.UI.WebControls.DNNMenu.MenuRenderMode), ddlRenderMode.SelectedValue)
        If Me.NavMenu.RenderMode = DotNetNuke.UI.WebControls.DNNMenu.MenuRenderMode.UnorderedList Then
            lnkNavCss.Href = "~/navigation/navlist.css"
        Else
            lnkNavCss.Href = "~/navigation/nav.css"
        End If

        Dim oXML As System.Xml.XmlDocument = New System.Xml.XmlDocument
        oXML.Load(Server.MapPath(FormUtil.AppPath(Me.Page) & "/navigation/navigation.xml"))
        Dim sUrl As String
        Dim oNode As XmlNode
        For Each oNode In oXML.SelectNodes("//n[@url]")
            sUrl = oNode.Attributes("url").Value
            oNode.Attributes("url").Value = FormUtil.AppPath(Me.Page) & sUrl
        Next
        For Each oNode In oXML.SelectNodes("//n[@img]")
            sUrl = oNode.Attributes("img").Value
            oNode.Attributes("img").Value = FormUtil.AppPath(Me.Page) & sUrl
        Next

        Try
            SetVersionInfo(oXML)
        Catch ex As Exception
        End Try

        Me.NavMenu.LoadXml(oXML.OuterXml)
        If Me.IsPostBack = False Then
            Me.NavMenu.ChildArrowImage = FormUtil.AppPath(Me.Page) & Me.NavMenu.ChildArrowImage
            Me.NavMenu.RootArrowImage = FormUtil.AppPath(Me.Page) & Me.NavMenu.RootArrowImage
        End If

    End Sub

    Private Sub SetVersionInfo(ByVal oXml As XmlDocument)
        Dim oNode As XmlNode = oXML.SelectSingleNode("//n[@txt='About']")
        Dim sClientAPIAssemblyVersion As String = "?"
        Dim sWebControlsAssemblyVersion As String = "?"

        sClientAPIAssemblyVersion = GetType(ClientAPI.ClientFunctionality).Assembly.FullName 'System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetAssembly(GetType(DotNetNuke.UI.Utilities.ClientAPI)).Location).FileVersion
        sWebControlsAssemblyVersion = GetType(DotNetNuke.UI.WebControls.DNNMenu).Assembly.FullName 'System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetAssembly(GetType(DotNetNuke.UI.WebControls.DNNNode)).Location).FileVersion
        oNode.Attributes("js").Value = String.Format(oNode.Attributes("js").Value, sClientAPIAssemblyVersion, sWebControlsAssemblyVersion)
    End Sub

    Public Function GetDocType() As String
        Return FormUtil.GetDocType(ddlDocType.SelectedValue)
    End Function

    Public Function GetHtmlNamespace() As String
        Return FormUtil.GetHtmlNamespace(ddlDocType.SelectedValue)
    End Function

End Class

